USE GESTION2
go

IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO') IS NOT NULL 
   BEGIN
      DROP PROCEDURE dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO 
      IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO') 
      IS
      NOT NULL 
         PRINT 
         '<<< FAILED DROPPING PROCEDURE dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO >>>'
      ELSE
         PRINT 
         '<<< DROPPED PROCEDURE dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO >>>' 
   END
go

SET ANSI_NULLS ON
go

SET QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE WASP_D0005_CREA_TABLA_FECHA_INGRESO 
AS
   SELECT ctnro,
      ctccli,
      MAX(Z07334FEC) AS FINGRTRABA
   INTO dbo.mt_fecha_ingreso 
   FROM fsd008 (nolock), z07334 (nolock) 
   WHERE ctccli IN (3, 4, 5) 
   AND ctnro = Z07334CTA 
   AND Z07304COD = 1 
   GROUP BY ctnro, ctccli
go



SET ANSI_NULLS OFF
go

SET QUOTED_IDENTIFIER OFF
go

IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO') IS NOT NULL 
   PRINT '<<< CREATED PROCEDURE dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO >>>' 
ELSE
   PRINT 
   '<<< FAILED CREATING PROCEDURE dbo.WASP_D0005_CREA_TABLA_FECHA_INGRESO >>>'
go
